package com.diablo.sitemanager.controller;

import com.diablo.sitemanager.dao.TagMapper;
import com.diablo.sitemanager.service.ArticleService;
import com.diablo.sitemanager.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Created by diablo13064 on 2018/5/22.
 * 管理跳转页，helloworld
 */
@Controller
@RequestMapping("/admin")
public class PageController {
    @Autowired
    TagService tagService;
    @Autowired
    ArticleService articleService;
    //管理首页
    @RequestMapping("/home")
    public String homePage(ModelMap modelMap) {
        modelMap.addAttribute("pageName", "后台管理");
        return "admin/index";
    }

    @RequestMapping("/statistics")
    public String statistics(ModelMap modelMap) {
        modelMap.addAttribute("pageName", "统计信息");
        return "admin/statistics";
    }
    //博客管理
    @RequestMapping("/manage_article")
    public String manageAritcle(ModelMap modelMap,@RequestParam(value = "pageNum", required = false, defaultValue = "1")int pageNum,
    @RequestParam(value = "pageSize",required = false,defaultValue = "8")int pageSize) {
        modelMap.addAttribute("pageName", "博客管理");
        modelMap.addAttribute("articleList", articleService.findAllArticle(pageNum,pageSize));
        return "admin/manage_article";
    }
    //编辑管理
    @RequestMapping("/edit_article")
    public String editAritcle(ModelMap modelMap) {
        modelMap.addAttribute("pageName", "博客编辑");
        modelMap.addAttribute("tagList", tagService.findAllTag());
        return "admin/edit_article";
    }
    //评论管理
    @RequestMapping("/manage_comment")
    public String manageComment(ModelMap modelMap) {
        modelMap.addAttribute("pageName", "评论管理");
        return "admin/manage_comment";
    }

}
